//	Company:	HTHK
//	NAME:	    ProjectSearch.java
//	TITLE:	    The maintence of Project in Time Sheet System
//	FUNCTION:	Search from DB of class Project associate with the table
//	BY:	        Kodak Xu
//	DATE:	    09/12/2003
//	Update_by	Poly Li
//	Update_date	16-01-2004
//	Update_by	Beyes Xia
//	Update_date	2004-2-13 17:42
// --------------------------------------------------------------
// MODIFICATION HISTORY
// --------------------------------------------------------------
//	CR Log #:  99999  BY:  XXXX   DATE:  dd/mm/yyyy
//	ERROR:	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//	FIX:	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// --------------------------------------------------------------
package tss.project;

import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;
import java.sql.*;

import com.ffpc.sql.*;
import com.ffpc.struts.StrutsMessage;

import tss.common.DBServlet2;

public class ProjectSearch extends DBServlet2 
{
	@Override
	protected String perform(HttpServletRequest request,
                             HttpServletResponse response,
                             StrutsMessage message)
    throws  ServletException,
            IOException,
            SQLException,
            DataException,
            Exception
   {
	  String projectNameStr = "";
      String projectCategoryNameStr = "";
      String commentsStr = "";
      //Add by Poly Li
      String chargeableStr = "";
	  String fromStr = "";
	  String toStr = "";
	  
	  //Add By : Beyes Xia//
	  String projectGroupNameStr = "";
	  if(request.getParameter("project_group") != null)
	  {
	  	projectGroupNameStr = request.getParameter("project_group");
	  }
	  //Add Date : 2004-2-13 17:29 //
	  
      if (request.getParameter("project_name") != null) {
      	  projectNameStr = request.getParameter("project_name");
      }
      if (request.getParameter("project_category") != null) {
      	  projectCategoryNameStr = request.getParameter("project_category");
      }
	  if (request.getParameter("comments") != null) {
		  commentsStr = request.getParameter("comments");
	  }
    if (request.getParameter("chargeable_ind") != null) 
		  chargeableStr = request.getParameter("chargeable_ind");
	  
	  if ((request.getParameter("year_from")!=null && request.getParameter("year_from").length()!=0) && (request.getParameter("month_from")!=null && request.getParameter("month_from").length()!=0)) 
		  fromStr = request.getParameter("year_from")+"/"+request.getParameter("month_from");

	  if ((request.getParameter("year_to")!=null && request.getParameter("year_to").length()!=0) && (request.getParameter("month_to")!=null && request.getParameter("month_to").length()!=0)) 
		  toStr = request.getParameter("year_to")+"/"+request.getParameter("month_to");
	//Add by Poly Li
      ProjectBean project = ProjectProcess.createBean();
      project.setProject_name(projectNameStr);
      project.setProject_category_name(projectCategoryNameStr);
      project.setComments(commentsStr);
      //Add by Poly Li
      project.setChargeable_ind(chargeableStr);
	project.setEffective_range_from(fromStr);
	project.setEffective_range_to(toStr);
	
	//Add By : Beyes Xia//
	project.setProject_group_name(projectGroupNameStr);
	// Add Date : 2004-2-13 17:31//
	 
      ProjectBean[] projects = ProjectProcess.find(this.getConnection(),project);
      if (projects==null || projects.length==0)
      {
          message.setMessage("No record, please input another criteria.");
          return "tss/project/ProjectSearch.jsp";
      }
      else if (projects.length==1)
      {
          request.setAttribute("project",projects[0]);
          return "tss/project/Project.jsp?formAction=Update";
      }
      else
      {
          request.setAttribute("projects",projects);
          return "tss/project/ProjectList.jsp";
      }
   }
}